package com.wangnian.task.service;

import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by wangnian on 2017/3/8.
 */
@Service
@DisallowConcurrentExecution
@PersistJobDataAfterExecution
public class JobTask implements Job {

    @Autowired
    ExecuteTaskService executeTaskService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap jobDataMap = jobExecutionContext.getMergedJobDataMap();
        String url = jobDataMap.get("url").toString();
        String bodyParameter = (String) jobDataMap.get("bodyParameter");
        String identityKey = (String) jobDataMap.get("identityKey");
        String description = (String) jobDataMap.get("description");
        boolean ifDisposable = (boolean) jobDataMap.get("ifDisposable");
        try {
            executeTaskService.execute(url, bodyParameter, identityKey, description, ifDisposable);
        } catch (Exception ex) {
        }
    }
}
